<style type="text/css">
	.vote_ul li{
		height: 37px;
		margin-bottom : 3px;
	}
	.vote_ul li input {
		float: left;
		width: 60%;
	}
	.vote_ul li .operate {
		margin-left: 6px;
		display: block;
		float: left;
		cursor: pointer;
		width: 30%;
	}
	.vote_ul li a{
		font-size:19px;
	}
	.form-box {
		border: 1px solid #ccc;
		padding: 15px 15px 0px 15px;
		margin-bottom: 15px;
		width: 662px;
		float: left;
	}
	.form-box .col-sm-5 {
		width: 530px
	}
	.form-box .col-sm-5 input{
	  width: 450px;
	}
	.form-box .form-group label{
		width: 100px;
		margin-left: 17px;
	}
	.form-box  .vote_ul li .operate {
		width: 40px;
	}
	.form-box  .col-sm-4 {
	  width: 476px;
	}
	 .form-box-left .form-box-t {
		padding-right: 29px;
	}
</style>
<form action="" class="form-horizontal" role="form">
	<div class="form-group">
		<label class="col-sm-1 control-label">投票标题</label>
		<div class="col-sm-5">
			<input type="text" id="title" class="form-control" name="title" placeholder="" datatype="*" value="{$vote.title}"/>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">投票说明</label>
		<div class="col-sm-5">
			<textarea id="desc" name="desc" class="form-control">{$vote.desc}</textarea>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-1 control-label">提交返回文本</label>
		<div class="col-sm-5">
			<textarea id="result_text" name="result_text" class="form-control">{$vote.result_text}</textarea>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-1 control-label">选择方式</label>
		<div class="col-sm-5">
			{$vote.selectOptionsRadio}
		</div>
	</div>
	<div class="form-group" id="options-down" style="display:none;">
        <label class="col-sm-1 control-label">选项个数</label>
        <div class="col-sm-5">
            <input type="number"  class="form-control" name="select_items" min="1" value="{$vote.select_items}">
        </div>
  </div>
  <div class="form-group" >
        <label class="col-sm-1 control-label">每天投票次数</label>
        <div class="col-sm-5">
            <input type="number"  class="form-control" name="vote_times" min="1" value="{$vote.select_items}">
        </div>
  </div>
   <div class="form-group">
      <label class="col-sm-1 control-label">展览图片</label>
     <div class="col-sm-4">
        <div class="image-result-content">
          <img id="logo-result" class="margin-bottom" src="http://wmei-wmei5.stor.sinaapp.com/2014-08-14/2014081416200619481919.jpg">
        </div>
        <input type="text" id="image-y" name="pic" class="form-control margin-bottom" value="{$vote.pic}"/>
        <input type="file" id="image_upload-y" />
      </div>
  </div>
	<div class="form-box-left"><label class="col-sm-1 control-label form-box-t">选择项目</label></div>	
	<div class="form-box" id="form-box">	
	   <if condition="$vote['answer'] && count($vote['answer']) gt 0">
       <volist id="vo" name="vote['answer']" key="key">
		   <div class="form-box-b">
				<div class="form-group">
					<label class="col-sm-1 control-label">选项标题{$key}</label>
					<div class="col-sm-5">
						<ul class="vote_ul">					
							<li>
								<input name="answer[{$key-1}][answer]" type="text" class="form-control answer" value="{$vo.answer}"/>
								<input name="answer[{$key-1}][id]" type="hidden" class="answer_id" value="{$vo.id}"/>
								<span class="operate"><a class="add">+</a> / <a class="del">-</a></span>
							</li>								
						</ul>
					</div>
				</div>
				<div class="form-group" >
			        <label class="col-sm-1 control-label">选项图片</label>
			        <div class="col-sm-4">
			            <div class="image-result-content">
			                <img id="image-result-{$key}" style="width:60px;" class="margin-bottom" />
			            </div>
			            <input type="text" id="image-{$key}" name="image[]" class="form-control margin-bottom" value={$vo.pic} />
			            <input type="file" name="image_upload" id="image_upload-{$key}" />
			        </div>            
			    </div>
		   </div>
	   </volist>
       <else/>
           <div class="form-box-b">
                <div class="form-group">
                    <label class="col-sm-1 control-label">选项标题</label>
                    <div class="col-sm-5">
                        <ul class="vote_ul">    
                             <li>
                                 <input name="answer[][answer]" type="text" class="form-control answer"/>
                                 <span class="operate"><a class="add">+</a> / <a class="del">-</a></span>
                             </li>
                        </ul>
                    </div>
                </div>
                <div class="form-group" >
                    <label class="col-sm-1 control-label">选项图片</label>
                    <div class="col-sm-4">
                        <div class="image-result-content">
                            <img id="image-result-1" style="width:60px;" class="margin-bottom" />
                        </div>
                        <input type="text" id="image-1" name="image[]" class="form-control margin-bottom" />
                        <input type="file" name="image_upload" id="image_upload-1" />
                   </div>            
                </div>
           </div>
        </if>
    </div>
	<div class="form-group">
		<div class="col-sm-offset-1 col-sm-8">
			<a class="btn btn-default" onclick="javascript:history.go(-1)">返回上页</a>
			<a class="btn btn-default" onclick="self.location=document.referrer">返回上页并刷新</a>
			<input type="hidden" name="id" value="{$vote.id}"/>
			<button type="submit" class="btn btn-primary submit" data-loading-txt="提交中，请稍后……" data-ajax-url="__CONTROLLER__/save">保存更改</button>
		</div>
    </div>
</form>

<script type="text/javascript">
	$(function() {
		for(var i=1;i<$('#form-box .form-box-b').size()+1;i++){
			oUploadify(i);
		}
		oUploadify("y");
		oInitial();
	});
</script>
<!-- uploadify -->
<link rel="stylesheet" href="__PUBLIC__/Style/Common/uploadify/uploadify.css">
<script type="text/javascript" src="__PUBLIC__/Style/Common/uploadify/jquery.uploadify.min.js?{:rand(0,9999)}"></script>
<script type="text/javascript">
	function oAppend(obj){
	      $("#form-box").append(
			  "<div class='form-box-b'><div class='form-group'><label class='col-sm-1 control-label'>选项标题</label><div class='col-sm-5'><ul class='vote_ul'><li><input name='answer[][answer]' type='text' class='form-control answer' /> <span class='operate'><a class='add'>+</a> / <a class='del'>-</a></span></li></ul></div></div><div class='form-group' id='list-img'><label class='col-sm-1 control-label'>选项图片</label><div class='col-sm-4'><div class='image-result-content'><img id='image-result-"+
		      obj+"' style='width:60px;' class='margin-bottom' /></div><input type='text' id='image-"+
		      obj+"' name='image[]' class='form-control margin-bottom' /><input type='file' name='image_upload' id='image_upload-"+
		      obj+"' /></div></div></div>"
	      )
	      $("#image_upload-"+obj).uploadify({
	          'multi'         :   false,
	          'fileSizeLimit' :   '200kb',
	          'buttonText'    :   '选择图片',
	          'fileTypeDesc'  :   'Image Files',
	          'fileTypeExts'  :   '*.jpg; *.png',
	          'swf'           :   '__PUBLIC__/Style/Common/uploadify/uploadify.swf',
	          'uploader'      :   '__MODULE__/Upload/uploadOne',
	          'onUploadSuccess'   : function(data, res){  
	              var url = eval("(" + res + ")").extra.url;
	              $("#image-result-"+obj).attr("src", url);
	              $("#image-"+obj).val( url );             
	          }
	      });
	}
	function oInitial(){
		$("#form-box").delegate(".add","click",function(){
			oAppend($(".uploadify").size()+1);
	   })
	   $("#form-box").delegate(".del","click",function(){
	        if( $("#form-box .form-box-b").size() > 1 ) {
	               $(this).parents('.form-box-b').remove();
	        }
	   })
	}
	function oUploadify(obj){
	    $("#image_upload-"+obj).uploadify({
	        'multi'         :   false,
	        'fileSizeLimit' :   '200kb',
	        'buttonText'    :   '选择图片',
	        'fileTypeDesc'  :   'Image Files',
	        'fileTypeExts'  :   '*.jpg; *.png',
	        'swf'           :   '__PUBLIC__/Style/Common/uploadify/uploadify.swf',
	        'uploader'      :   '__MODULE__/Upload/uploadOne',
	        'onUploadSuccess'   : function(data, res){
	            var url = eval("(" + res + ")").extra.url;
	            $("#image-result-"+obj).attr("src", url);
	            $("#image-"+obj).val( url );
	        }
	    });  
	}
/* 选择方式隐藏与显示 */
 $(function(){
	   $("#logo_upload").uploadify({
	        'multi'     : false,
	        'fileSizeLimit' :   '200kb',
	        'buttonText'  : '选择图片',
	        'fileTypeDesc'  :   'Image Files',
	        'fileTypeExts'  :   '*.jpg; *.png',
	        'swf'     :   '/Public/Style/Common/uploadify/uploadify.swf',
	        'uploader'    :   '/index.php/My/Upload/uploadOne',
	        'onUploadSuccess' : function(data, res){
	          
	          var url = eval("(" + res + ")").extra.url;
	          $("#logo-result").attr("src", url);
	          $("#pic").val( url );
	          
	        }
	    });

	 if($("#select_options_0").is(':checked')){
		 $("#options-down").hide();
	 }else{
		 $("#options-down").show();
	 };
	 $("#select_options_0").click(function(){
		 $("#options-down").hide();
	 });
	 $("#select_options_1").click(function(){
     $("#options-down").show();
   });
 })
</script>